package com.fc.test.service;

import java.util.List;
import java.util.Arrays;

import com.fc.test.model.auto.EntCollect;
import com.fc.test.model.auto.EntCollectExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.util.StrUtil;
import com.fc.test.common.base.BaseService;
import com.fc.test.common.support.ConvertUtil;
import com.fc.test.mapper.auto.EntInfoMapper;
import com.fc.test.model.auto.EntInfo;
import com.fc.test.model.auto.EntInfoExample;
import com.fc.test.model.custom.Tablepar;
import com.fc.test.util.SnowflakeIdWorker;
import com.fc.test.util.StringUtils;

/**
 * 企业信息表 EntInfoService
 * @Title: EntInfoService.java 
 * @Package com.fc.test.service 
 * @author DrRic_自动生成
 * @email drhyz@qq.com
 * @date 2020-07-05 17:22:14  
 **/
@Service
public class EntInfoService implements BaseService<EntInfo, EntInfoExample>{
	@Autowired
	private EntInfoMapper entInfoMapper;
	
      	   	      	      	      	      	      	      	      	      	      	      	
	/**
	 * 分页查询
	 * @param pageNum
	 * @param pageSize
	 * @return
	 */
	 public PageInfo<EntInfo> list(Tablepar tablepar,EntInfo record){
	        EntInfoExample testExample=new EntInfoExample();
		 	if(record.getEid()!=null){
				testExample.createCriteria().andEidEqualTo(record.getEid());
				testExample.setOrderByClause("eid ASC");
				if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
					testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
				}
				PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
				List<EntInfo> list= entInfoMapper.selectByExample(testExample);
				PageInfo<EntInfo> pageInfo = new PageInfo<EntInfo>(list);
				return  pageInfo;
			}
	        return new PageInfo<>();
	 }

	public PageInfo<EntInfo> listForSys(Tablepar tablepar, EntInfo record){
		EntInfoExample testExample=new EntInfoExample();
		testExample.createCriteria().andLikeQuery(record);
		testExample.setOrderByClause("eid ASC");
		if(StrUtil.isNotEmpty(tablepar.getOrderByColumn())) {
			testExample.setOrderByClause(StringUtils.toUnderScoreCase(tablepar.getOrderByColumn()) +" "+tablepar.getIsAsc());
		}
		PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
		List<EntInfo> list= entInfoMapper.selectByExample(testExample);
		PageInfo<EntInfo> pageInfo = new PageInfo<EntInfo>(list);
		return  pageInfo;
	}

	@Override
	public int deleteByPrimaryKey(String ids) {
					
			Integer[] integers = ConvertUtil.toIntArray(",", ids);
			List<Integer> stringB = Arrays.asList(integers);
			EntInfoExample example=new EntInfoExample();
			example.createCriteria().andEidIn(stringB);
			return entInfoMapper.deleteByExample(example);
			
				
	}
	
	
	@Override
	public EntInfo selectByPrimaryKey(String id) {
				
			Integer id1 = Integer.valueOf(id);
			return entInfoMapper.selectByPrimaryKey(id1);
				
	}

	
	@Override
	public int updateByPrimaryKeySelective(EntInfo record) {
		return entInfoMapper.updateByPrimaryKeySelective(record);
	}
	
	
	/**
	 * 添加
	 */
	@Override
	public int insertSelective(EntInfo record) {
				
		record.setEid(null);

		entInfoMapper.insertSelective(record);
		return record.getEid();
	}
	
	
	@Override
	public int updateByExampleSelective(EntInfo record, EntInfoExample example) {
		
		return entInfoMapper.updateByExampleSelective(record, example);
	}

	
	@Override
	public int updateByExample(EntInfo record, EntInfoExample example) {
		
		return entInfoMapper.updateByExample(record, example);
	}

	@Override
	public List<EntInfo> selectByExample(EntInfoExample example) {
		
		return entInfoMapper.selectByExample(example);
	}

	
	@Override
	public long countByExample(EntInfoExample example) {
		
		return entInfoMapper.countByExample(example);
	}

	
	@Override
	public int deleteByExample(EntInfoExample example) {
		
		return entInfoMapper.deleteByExample(example);
	}
	
	/**
	 * 检查name
	 * @param entInfo
	 * @return
	 */
	public int checkNameUnique(EntInfo entInfo){
		EntInfoExample example=new EntInfoExample();
		example.createCriteria().andEnameEqualTo(entInfo.getEname());
		List<EntInfo> list=entInfoMapper.selectByExample(example);
		return list.size();
	}


}
